//
//  MyAskViewController.m
//  DoctorFAQs
//
//  Created by zjq on 17/2/9.
//  Copyright © 2017年 zjq. All rights reserved.
//

#import "MyAskViewController.h"
#import "ZMyAskUntilView.h"
#import "ZMyAskAlreadyView.h"

#import "ZLookFriendDeatilViewController.h"
@interface MyAskViewController ()<ZMyAskUntilViewDelegate,ZMyAskAlreadyDelegate> {
    UIButton * _untilButton;
    UIButton * _alreadybutton;
    UIButton * _currentBtn;
    UIView * _whiteView;
    UIView * _greenView;
}

@property (nonatomic,strong)ZMyAskUntilView * AskUntilView;  // 未回复
@property (nonatomic,strong)ZMyAskAlreadyView * AskAlreadyView; // 已回复
@end

@implementation MyAskViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initialzeDatas];
    [self initlizeInterface];
}
- (void)initialzeDatas {
    
}
- (void)initlizeInterface {
    self.view .backgroundColor = MYGRAYCOLOR;
    
    _whiteView = [[UIView alloc] init];
    _whiteView.backgroundColor = [UIColor whiteColor];
    _whiteView.frame = CGRectMake(0, 2, SCREEN_Height, 49*ysIZE);
    _greenView = [[UIView alloc] init];
    _greenView.backgroundColor = MYGREENColor;
    _greenView.frame = CGRectMake(55*xsIZE, 45*ysIZE, 50*xsIZE, 2*ysIZE);
    
    _untilButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_untilButton setTitle:@"待回复" forState:UIControlStateNormal];
    [_untilButton addTarget:self action:@selector(uitilButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    _untilButton.frame = CGRectMake(30*xsIZE,5*ysIZE ,100*xsIZE,40*ysIZE);
    [self selectedOn:_untilButton];
    _currentBtn = _untilButton;
    _alreadybutton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_alreadybutton setTitle:@"已回复" forState:UIControlStateNormal];
    [_alreadybutton addTarget:self action:@selector(alreadyButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [_alreadybutton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _alreadybutton.frame = CGRectMake(160*xsIZE,5*ysIZE , 100*xsIZE, 40*ysIZE);
    [self.view addSubview:_whiteView];
    [self.view addSubview:_greenView];
    [self.view addSubview:_untilButton];
    [self.view addSubview:_alreadybutton];
    [self.view addSubview:self.AskUntilView];
    
    
    
}
// 待回复按钮和已回复按钮
- (void)uitilButtonAction:(UIButton *)sender {
    if (sender.selected) {
        return;
    }
    sender.selected = !sender.selected;
    [self selectedOn:sender];
    [self selectedOff:_currentBtn];
    _currentBtn.selected = NO;
     _currentBtn = sender;
    _greenView.frame = CGRectMake(55*xsIZE, 45*ysIZE, 50*xsIZE, 2*ysIZE);
    [self.AskAlreadyView removeFromSuperview];
    
}
- (void)alreadyButtonAction:(UIButton *)sender {
    if (sender.selected) {
        return;
    }
    sender.selected = !sender.selected;
    [self selectedOn:sender];
    [self selectedOff:_currentBtn];
    _currentBtn.selected = NO;
    _currentBtn = sender;
    [self.view addSubview:self.AskAlreadyView];
   _greenView.frame = CGRectMake(185*xsIZE, 45*ysIZE, 50*xsIZE, 2*ysIZE);
}
//-(void)

- (void)selectedOn:(UIButton *)sender{
    [sender setTitleColor:MYGREENColor forState:UIControlStateNormal];
}
- (void)selectedOff:(UIButton *)sender{
    [sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
}


//待回复界面协议实现
- (void)selectCellWith:(NSInteger)index {
    NSLog(@"跳转%ld",(long)index);
    ZLookFriendDeatilViewController * vc = [[ZLookFriendDeatilViewController alloc] init];
    [self.navigationController pushViewController:vc animated:NO];
}
- (void)cancelInfoWith:(NSInteger)index {
    NSLog(@"撤销%ld",index);
    
}
// 已回复界面协议的实现
- (void)selectAlreadyWith:(NSInteger)index{
    NSLog(@"已回复界面跳转");
    ZLookFriendDeatilViewController * vc = [[ZLookFriendDeatilViewController alloc] init];
    [self.navigationController pushViewController:vc animated:NO];
}


// lazy
- (ZMyAskUntilView *)AskUntilView {
    if (_AskUntilView) {
        return _AskUntilView;
    }
    _AskUntilView = [[ZMyAskUntilView alloc] init];
    _AskUntilView.frame = CGRectMake(0,50*ysIZE, SCREEN_Width, SCREEN_Height-159*ysIZE);
    _AskUntilView.Undelegate = self;
    return _AskUntilView;
}

- (ZMyAskAlreadyView *)AskAlreadyView {
    if (_AskAlreadyView) {
        return _AskAlreadyView;
    }
    _AskAlreadyView = [[ZMyAskAlreadyView alloc] init];
    _AskAlreadyView.frame = CGRectMake(0,50*ysIZE, SCREEN_Width, SCREEN_Height-159*ysIZE);
    _AskAlreadyView.alreadyDelegate = self;
    return _AskAlreadyView;
}
@end
